package userRepository

import (
	"fmt"
	"sg-backend/app/entity/userQuery"
	"sg-backend/global"
	"sg-backend/model/user"
)

func GetUserByAccount(qo *userQuery.GetUserByAccountQo) *user.User {
	var _user = new(user.User)
	tx := global.DB.Where("username = ?", qo.Account).First(_user)
	if tx == nil {
		fmt.Println("? ：用户名匹配不到，开始匹配手机号...", qo.Account)
		tx = global.DB.Where("mobile = ?", qo.Account).First(_user)
		if tx == nil {
			fmt.Println("? ：手机号匹配不到，开始匹配邮箱...", qo.Account)
			tx = global.DB.Where("email = ?", qo.Account).First(_user)
			if tx == nil {
				return nil
			}
		}
	}
	return _user
}

func GetUserById(userId uint) *user.User {
	var _user = new(user.User)
	global.DB.Where("id = ?", userId).First(_user)
	return _user
}
